require(["../../conf/config.js"], function() {
	require(["jquery", "jquery-ui", "jquery-cookie", ], function($, jqui, jqcookie) {
			console.log("成功加载js");

			$("#contanter").css("minHeight", 439);

			$(".email input").focus(function() { //获得焦点 输入框变颜色
				$(this).css({
					border: "1px solid #3795FB"
				})
			})
			let results = [];
			$(".email input").blur(function() { // let email = $(".email input").val();
				if (/^\w+@\w+(\.\w+)+$/.test(this.value)) {
					results[0] = true;
					$(".email h5").css({
						display: "none"
					});
				} else {
					$(".email h5").css({
						display: "block"
					});
					results[0] = false;
				}
			})
			var newwid;
			var email_value;
			$("#movebtn").draggable({ // 验证按钮 实现拖拽
				containment: "parent",
				axis: "x",
				//revert: true,
				start: function() { //点开始

				},
				drag: function() { // 拖拽过程中
					newwid = $("#movebtn").css("left");
					let aa = parseInt(newwid);

					$("#cover").css({
						width: newwid
					});


				},
				stop: function() { //点结束
					newwid = $("#movebtn").css("left");
					let aa = parseInt(newwid);
					//console.log(aa);
					if (aa < 240) {
						// $("#movebtn").mouseleave(function(){
						//console.log(aa);
						$("#cover").animate({
							width: 0
						}, 300);
						$("#movebtn").animate({
							left: 0
						}, 300);
						results[1] = false;
						// })
					} else {
						$("#cover").animate({
							width: "258px"
						}, 200);
						$("#movebtn").animate({
							left: "258px"
						}, 200);
						$("#cover").css({
							"width": "258px"
						});
						results[1] = true;
						//$("#movebtn").css("left","258px");
					}
				}
			});
			$("#cover").css({
				width: "newwid"
			});
			$("#checkbox1").click(function() { //来判断checkbox 的类型true / false
				if ($("#checkbox1").prop("checked") == true) {
					$("#nextstep").css({
						background: "#FF4001"
					});
					$("#nextstep span").css({
						color: "#ffffff"
					});
					results[2] = true;
				} else {
					$("#nextstep").css({
						background: "#ededed"
					});
					$("#nextstep span").css({
						color: "#999999"
					});
					results[2] = false;
				}

			})
			$("#nextstep span").click(function() {

				var res = results.every(function(item) {
					return item === true;
				});
				if (results.length == 3 && res == true) { //如果成功

					email_value = $(".email input").val();

					$.cookie('email', email_value, {
						expires: 7,
						path: '/'
					});
					$("#step ul li:nth-child(2)").addClass("active"); // step 2 classname= active；

					$(document).ready(function() {
						$.getScript("regist.js");
						$("#contanter").load("step1.html", function() {
							var sc = document.createElement("script");
							sc.src = "regist.js";
							$("#contanter").html($("#step2").html());

							$("#loginname").html(email_value);
						})
					});


					/////////传递email

				} else {
					alert("请先纠正输入错误，再提交！！");
					$("#step ul li:nth-child(2)").removeClass("active");
				}
			})
			///////////////////////step2///////////////////////////////////////////////////

			$(".form-item input").focus(function() { // 所有input获得焦点
				if ($(this).val() == "") {
					$(this).siblings().last().css({
						display: "block"
					});
				} else {
					$(this).siblings().last().css({
						display: "none"
					});
				}
			})
			$(".form-item input").blur(function() { // 所有inputshiqu焦点
				if ($(this).val() == "") {
					$(this).siblings().last().css({
						display: "none"
					});
				}
			})
			$(".form-item input").focus(function() { // 所有inputshiqu焦点
				if ($(this).val() == "") {
					$(this).next().next().css({
						display: "block"
					});
					$(this).next().css({
						display: "none"
					});
				}
			})
			let mmval;
			$("#dlmm").focus(function() { //密码1 获得焦点 判断
				$("#kk").css({
					display: "block"
				}); //密码强度 判断
				$(this).keyup(function() {
					mmval = $(this).val(); //密码 mmval
					console.log(mmval);
					$("span").removeClass("btnmactive");
					$(this).text(function() {
						let hasSpecial = /[^a-zA-Z0-9]/.test(this.value);

						let hasLetter = /[a-zA-Z]/.test(this.value);
						let hasNumber = /[0-9]/.test(this.value);
						if (hasSpecial) { //强 	
							$(".btnm:nth-child(2)").addClass("btnmactive");
							$(".btnm:nth-child(3)").addClass("btnmactive");
							$(".btnm:nth-child(4)").addClass("btnmactive");

						} else if (hasLetter && hasNumber) { //中
							$(".btnm:nth-child(2)").addClass("btnmactive");
							$(".btnm:nth-child(3)").addClass("btnmactive");
							$(".btnm:nth-child(4)").removeClass("btnmactive");
						} else { //弱
							$(".btnm:nth-child(2)").addClass("btnmactive");
							$(".btnm:nth-child(3)").removeClass("btnmactive");
							$(".btnm:nth-child(4)").removeClass("btnmactive");
						}
					})

				})
			})
			let endres = [];
			$("#dlmm").blur(function() { //密码1 失去焦点 判断
				$("#kk").css({
					display: "none"
				});
				if (/(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^.{6,16}$/.test(this.value)) {
					endres[0] = true;
					$(".mm1 h5").css({
						display: "none"
					});
				} else {
					$(".mm1 h5").css({
						display: "block"
					});
					endres[0] = false;
				}
			})
			let mm2val;
			$("#mm2").focus(function() { //密码2获得焦点判断
				if (mm2val == "") {
					$(".mm2 b").css({
						display: "none"
					});
				}
			})
			$("#mm2").blur(function() { //密码2失去焦点判断

				mm2val = $("#mm2").val();
				// mmval=$(this).val();
				console.log(mm2val);
				if (mm2val == mmval) {
					endres[1] = true;
					$(".mm2 h5").css({
						display: "none"
					});
				} else {
					$(".mm2 h5").css({
						display: "block"
					});
					endres[1] = false;
				}
			})

			$("#tel").blur(function() { //电话 
				if (/^1\d{10}$/.test(this.value)) {
					endres[2] = true;
					$(".tel h5").css({
						display: "none"
					});
					$(".tel b").css({
						display: "none"
					});
				} else {
					endres[2] = false;
					$(".tel h5").css({
						display: "block"
					});
					$(".tel b").css({
						display: "none"
					});
				}
			})
			$(".tel").focus(function() {
				if ($("#tel").val() == "") {
					$(".tel h5").css({
						display: "none"
					});
				}
			})
			$("#vipname").blur(function() { //会员名字

				if ($(this).val() == "") {
					$(".vipname h5:nth-child(0)").css({
						display: "none"
					})
				}
				if (/^\w{5,25}$/.test(this.value)) {
					endres[3] = true;
					$(".vipname h5").css({
						display: "none"
					});
				} else {
					endres[3] = false;
					$(".vipname h5").css({
						display: "block"
					});
				}
			})
			//点击确认键事件
			$(".okok").click(function() {//cooke
					$.cookie("vipname",$("#vipname").val(),{ expires: 7, path: '/' })
					var res2 = endres.every(function(item) {
						return item === true;
					});
					if (endres.length == 4 && res2 == true) { //如果成功
						$("#step ul li:nth-child(3)").addClass("active"); // step 3 classname= active；
						submit();
						$(document).ready(function() { // load step3 的html
							$.getScript("regist.js");
							$("#contanter").load("step1.html", function() {
								var sc = document.createElement("script");
								sc.src = "regist.js";
								$("#contanter").html($("#step3").html());
								$("#successbox i").html($.cookie("email"));
								$("#successbox #vpn").html($.cookie("vipname"));
							})
						});
					} else {
						alert("请先纠正输入错误，再提交！！");
						$("#step ul li:nth-child(3)").removeClass("active");
					}
				
			})

		function submit() {
			var inputs = document.getElementsByTagName("input");
			var country = document.getElementsByTagName("select")[0].value;
			var password = inputs[0].value;
			var tel = inputs[2].value;
			var vipname = inputs[3].value;
			var status = 0;
			var shopcar = [];
			var email_value = $("#loginname").html();
			var asum = 0;
			var message = {
				email_value,
				password,
				tel,
				vipname,
				country,
				status,
				shopcar, 
				asum
			};

			var cookiestr = getCookie("userlist");
			//检测cookie里是否有userlist
			if (!cookiestr) {
				var arr = [];
			} else {
				arr = JSON.parse(cookiestr);
			}
			//检测是否存在该用户，在此使用手机号作为每个用户的唯一标志
			var exsit = false;

			arr.forEach(function(item) {
				if (item.tel == message.tel) {
					exsit = true;
				}
			})

			if (!exsit) {;
				arr.push(message);
				
			} else {
				alert("该手机号已被使用！")
			}
			setCookie("userlist", JSON.stringify(arr), 7);


		}

		function getCookie(key) {
			var kvlist = document.cookie.split("; ");
			var kv = kvlist.find(function(item) {
				return item.split("=")[0] == key;
			});

			if (kv) {
				return kv.split("=")[1];
			}
		}

		function getNDaysAfter(n) {
			var now = new Date();
			now.setDate(now.getDate() + n);
			return now;
		}

		function setCookie(key, val, days) {
			document.cookie = key + "=" + val + "; expires=" + getNDaysAfter(days) + "; path= /"
		}
	})

})
